using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace CudaCalls
{
    public class CallCudaFunction
    {
            
        [DllImport("cudacluster.dll")] 
        static extern int init_cuda();

        [DllImport("cudacluster.dll")]
        static extern void run_pdist(float[] result, float[] input, uint size_x, uint size_y);

        [DllImport("cudacluster.dll")]
        static extern void run_linkage(float[] result, float[] input, uint size_y);
        
        [DllImport("cudacluster.dll")]
        static extern void lower_triangle(float[] output, float[] input, uint size_y);

        [DllImport("cudacluster.dll")]
        static extern void clustertree(float[] result, float[] input, uint size_y, uint num_clusters);

        public int Call_init_cuda()
        { 
            return init_cuda();
        }

        public float[] Call_run_pdist(float[] input, uint size_x, uint size_y)
        {

            float[] ret = new float[size_y*size_y];
            run_pdist(ret,input,size_x,size_y);

            return ret;
        }

        public float[] Call_run_linkage(float[] input, uint size_y)
        {

            float[] ret = new float[3*(size_y-1)];
            run_linkage(ret, input,  size_y);

            return ret;
        }

        public float[] Call_lower_triangle(float[] input, uint size_y)
        {
            float[] ret = new float[(size_y * (size_y-1)) / 2];
            lower_triangle(ret, input, size_y);
            
            return ret;
        } 

        public float[] Call_clustertree(float[] input, uint size_y, uint num_clusters)
        {
            float[] ret = new float[size_y];
            clustertree(ret, input, size_y, num_clusters);

            return ret;
        }
    }
}
